import { NextRequest, NextResponse } from 'next/server';
import UserModel from '@/models/user';
import { authMiddleware, TokenPayload } from '@/utils/auth';

// GET - 获取用户的所有实习经历
export async function GET(request: NextRequest) {
  try {
    // 验证用户身份
    const authResult = await authMiddleware(request);
    if (authResult instanceof NextResponse) {
      return authResult; // 返回错误响应
    }
    
    const decoded = authResult as TokenPayload;
    const userId = decoded.id;
    
    // 获取用户的实习经历
    const internships = await UserModel.getInternships(userId);
    
    console.log('获取到的实习经历:', internships);
    
    return NextResponse.json(internships, { status: 200 });
  } catch (error) {
    console.error('获取实习经历错误:', error);
    return NextResponse.json(
      { error: '服务器错误，请稍后再试' },
      { status: 500 }
    );
  }
} 